﻿using AutoMapper;
using IdentityServer4.EntityFramework.Entities;

namespace EMall.AdminGateway
{

    public static class IdentityServerMappers
    {
        static IdentityServerMappers()
        {
            Mapper = new MapperConfiguration(cfg => cfg.AddProfile<IdentityServerProfile>()).CreateMapper();
        }
        internal static IMapper Mapper { get; }
        public static IdentityServer4.Models.IdentityResource ToModel(this IdentityResource entity)
        {
            return entity == null ? null : Mapper.Map<IdentityServer4.Models.IdentityResource>(entity);
        }
        public static IdentityResource ToEntity(this IdentityServer4.Models.IdentityResource model)
        {
            return model == null ? null : Mapper.Map<IdentityResource>(model);
        }

        public static IdentityServer4.Models.ApiResource ToModel(this ApiResource entity)
        {
            return entity == null ? null : Mapper.Map<IdentityServer4.Models.ApiResource>(entity);
        }
        public static ApiResource ToEntity(this IdentityServer4.Models.ApiResource model)
        {
            return model == null ? null : Mapper.Map<ApiResource>(model);
        }

        public static IdentityServer4.Models.ApiScope ToModel(this ApiScope entity)
        {
            return entity == null ? null : Mapper.Map<IdentityServer4.Models.ApiScope>(entity);
        }
        public static ApiScope ToEntity(this IdentityServer4.Models.ApiScope model)
        {
            return model == null ? null : Mapper.Map<ApiScope>(model);
        }

        public static IdentityServer4.Models.Client ToModel(this Client entity)
        {
            return entity == null ? null : Mapper.Map<IdentityServer4.Models.Client>(entity);
        }
        public static Client ToEntity(this IdentityServer4.Models.Client model)
        {
            return model == null ? null : Mapper.Map<Client>(model);
        }
    }
}
